//
//  MyVipCardViewController.m
//  NeusoftHBSJSober
//
//  Created by Apple-21 on 15/11/9.
//  Copyright (c) 2015年 com.neusoftsober. All rights reserved.
//

#import "MyVipCardViewController.h"
#import "MHandleCardViewController.h"
#import "MVIPCardService.h"
#import "MDDataBaseUtil.h"
#import "MViewUtil.h"
#import "MyVipCardListModel.h"
#import "MMerchantVipCardViewController.h"
@interface MyVipCardViewController ()<UITableViewDataSource, UITableViewDelegate> {

    MHandleCardViewController *handleCardVC;
    MMerchantVipCardViewController *merchantVipCardVC;
}

- (IBAction)backAction:(UIButton *)sender;
- (IBAction)handleVIPCardAction:(UIButton *)sender;
@property (weak, nonatomic) IBOutlet UITableView *myTableView;
@property (nonatomic, strong) NSMutableArray *VIPCardMutArray;
@end

@implementation MyVipCardViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // 去掉下方多余的线
    self.myTableView.tableFooterView = [[UITableView alloc]init];
    // 
    self.myTableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
    self.VIPCardMutArray = [NSMutableArray array];
}
- (void)viewWillAppear:(BOOL)animated {

    [self getMyVipCardList];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

 
    return self.VIPCardMutArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *cellStr = @"identifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellStr];
        
        UILabel *companyNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH/2, 40)];
        companyNameLabel.textAlignment = NSTextAlignmentCenter;
        companyNameLabel.font = [UIFont fontWithName:nil size:13.0];
        companyNameLabel.textColor = [UIColor blackColor];
        [companyNameLabel setTag:101];
        [cell.contentView addSubview:companyNameLabel];
        
        UILabel *moneyLabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREENWIDTH/2, 0, SCREENWIDTH/2, 40)];
        moneyLabel.textAlignment = NSTextAlignmentCenter;
        moneyLabel.font = [UIFont fontWithName:nil size:13.0];
        moneyLabel.textColor = [UIColor blackColor];
        [moneyLabel setTag:102];
        [cell.contentView addSubview:moneyLabel];
        
    }
    MyVipCardListModel *model = [[MyVipCardListModel alloc]init];
    model = [self.VIPCardMutArray objectAtIndex:indexPath.row];
    
    ((UILabel *)[cell.contentView viewWithTag:101]).text = model.salemanName;
    ((UILabel *)[cell.contentView viewWithTag:102]).text = model.pickUpCash;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    MyVipCardListModel *model = [[MyVipCardListModel alloc]init];
    model = [self.VIPCardMutArray objectAtIndex:indexPath.row];
    merchantVipCardVC = [[MMerchantVipCardViewController alloc]init];
    merchantVipCardVC.myVipCardModel = model;
    merchantVipCardVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentViewController:merchantVipCardVC animated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (void)getMyVipCardList {

    [[MViewUtil instance]showLoadingText:@"正在加载..." targetView:self.view];
    [[MVIPCardService sharedClient]getMyVipCardWithUserID:[[MDDataBaseUtil userID]integerValue] isFriend:@"false" isUse:@"" completion:^(NSMutableArray *result){
        [[MViewUtil instance]hideLoadingTextFromTargetView:self.view];
        self.VIPCardMutArray = [NSMutableArray arrayWithArray:result];
        [self.myTableView reloadData];
    } failure:^(NSString *error){
    
        [[MViewUtil instance]showShortDurationMessage:error targetView:self.view];
    }];
}
- (IBAction)backAction:(UIButton *)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)handleVIPCardAction:(UIButton *)sender {
    handleCardVC = [[MHandleCardViewController alloc]init];
    handleCardVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentViewController:handleCardVC animated:YES completion:nil];
}
@end
